package com.ama.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileUtils {

    private static final String fromPath = "src/main/java/com/ama/utils/urltoImage/phantomjs/bbaidu.png";
    private static final String toPath = "C:\\Users\\AMAZZED\\Desktop";

    public static void main(String[] args) throws Exception {
        File fromFile = new File(fromPath);
        File toFile = new File("C:\\","newPic.png");
        copyFile(fromFile,toFile);
        System.out.println("复制成功！");
    }

    public static void copyFile(File fromFile, File toFile) throws Exception {
        FileInputStream is = new FileInputStream(fromFile);
        FileOutputStream os = new FileOutputStream(toFile);
        byte[] b = new byte[1024];
        int temp = 0;
        while ((temp = is.read(b)) != -1) {
            os.write(b, 0, temp);
        }
        is.close();
        os.close();
    }

}
